package com.spc.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.spc.constant.MessageConstant;
import com.spc.entity.PageResult;
import com.spc.entity.Result;
import com.spc.service.HealthPlanService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/healthPlan")
public class healthPlanController {

    @Reference
    private HealthPlanService healthPlanService;


    /**
     * 添加疾病库表
     * @param map
     * @return
     */
    @RequestMapping("/add")
    public Result addIllness(@RequestBody Map map){


        try {

            healthPlanService.add(map);

        }catch (Exception e){

            return new Result(false, MessageConstant.ADD_Illness_FAIL);

        }


        return new Result(true,MessageConstant.ADD_Illness_SUCCESS);

    }
    /**
     * 查询分页疾病项
     */
    @RequestMapping("/findPage")
    public PageResult findAll(@RequestBody Map map){

        PageResult pageResult = null;

       try {
           pageResult =  healthPlanService.findPage(map);

           return  pageResult;
       }catch (Exception e){

           e.printStackTrace();

           return pageResult;

       }





    }

    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Map map = healthPlanService.findById(id);
            return new Result(true,MessageConstant.QUERY_Illness_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false,MessageConstant.QUERY_Illness_FAIL);
        }
    }


    //编辑检查项
    @RequestMapping("/edit")
    public Result edit(@RequestBody Map map,Integer id){
        try {
            healthPlanService.edit(map,id);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false, MessageConstant.EDIT_Illness_FAIL);
        }

        return new Result(true, MessageConstant.EDIT_Illness_SUCCESS);
    }


    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            healthPlanService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            //说明服务调用失败
            return new Result(false, MessageConstant.DELETE_Illness_FAIL);
        }

        return new Result(true, MessageConstant.DELETE_Illness_SUCCESS);


    }

    //添加科室
    @RequestMapping("/addDepartments")
    public Result addDepartments(@RequestBody Map map){

        try {

            healthPlanService.addDepartments(map);

        }catch (Exception e){

            return new Result(false, MessageConstant.ADD_DEPARTMENT_FAIL);

        }


        return new Result(true,MessageConstant.ADD_DEPARTMENT_SUCCESS);



    }

    //回显科室
    @RequestMapping("/findAllDepartments")
    public Result findAllDepartments(){

        try {

           List<Map> list = healthPlanService.findAllDepartments();
            return new Result(true,MessageConstant.QUERY_Illness_SUCCESS,list);
        }catch (Exception e){

            return new Result(false, MessageConstant.QUERY_Illness_FAIL);

        }






    }











}
